package com.wl.api.controller.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.wl.api.common.utils.JsonObject;
import com.wl.api.common.utils.constant.ClientConstant;
import com.wl.api.controller.base.CommonController;
import com.wl.api.dto.system.SecurityChannelAreaServiceNetworkDTO;
import com.wl.api.dto.system.SecurityChannelAreaServicePartnerDTO;
import com.wl.api.model.system.SecurityChannelAreaLadderPrice;
import com.wl.api.model.system.SecurityChannelAreaService;
import com.wl.api.service.system.ISecurityChannelAreaLadderPriceService;
import com.wl.api.service.system.ISecurityChannelAreaServiceNetworkService;
import com.wl.api.service.system.ISecurityChannelAreaServicePartnerService;
import com.wl.api.service.system.ISecurityChannelAreaServiceService;
import com.wl.api.service.system.ISecurityChannelService;

/**
 * 用户首页查价接口服务
 * 
 * @author cj
 *
 */
@RestController
@RequestMapping("/external/customer/quote")
public class CustomerQuoteController extends CommonController {

	@Autowired
	ISecurityChannelService channelService;
	@Autowired
	ISecurityChannelAreaLadderPriceService areaLadderPriceService;
	@Autowired
	ISecurityChannelAreaServiceService areaServiceService;
	@Autowired
	ISecurityChannelAreaServicePartnerService areaServicePartnerService;
	@Autowired
	ISecurityChannelAreaServiceNetworkService areaServiceNetworkService;

	/**
	 * 1.根据重量查询渠道列表
	 * 
	 * @param fromId
	 * @param reachId
	 * @param weight
	 * @return
	 */
	@RequestMapping("/channel")
	public JsonObject getChannelList(@RequestParam Integer fromId, @RequestParam Integer reachId,
			@RequestParam String weight) {
		JsonObject json = JsonObject.getInstance();

		json.setData(channelService.queryChannelPrice(fromId, reachId, weight));
		setJsonMessage(json);
		return json;
	}

	/**
	 * 获取发货地 取件费
	 * 
	 * @return
	 */
	@RequestMapping(value = "/pickup/{fromId}", method = RequestMethod.GET)
	public JsonObject getFromIDPickUpItem(@PathVariable("fromId") Integer fromId) {
		JsonObject json = JsonObject.getInstance();
		areaLadderPriceService.getAreaLadderPricesByParam(SecurityChannelAreaLadderPrice.builder()
				.feeType(ClientConstant.FEE_TYPE_PICK_UP).areaId(fromId).build());

		return json;
	}
	/*
	 * version 1: old 服务费接口查询
	 * 
	 * @RequestMapping(value = "/service/{countryId}") public JsonObject
	 * getAreaServiceFee(@PathVariable("countryId") Integer countryId) { JsonObject
	 * json = JsonObject.getInstance(); SecurityAreaLadderExtendDTO data =
	 * areaLadderPriceService.getAreaLadderDetail(SecurityAreaLadderExtendDTO.
	 * builder().countryId(countryId).build()); json.setData(data);
	 * setJsonMessage(json); return json; }
	 */

	/**
	 * @desc 2.获取区域服务类型定义列表
	 * @param countryId
	 * @return
	 */
	@RequestMapping(value = "/service/{countryId}")
	public JsonObject getAreaServiceItem(@PathVariable("countryId") Integer countryId) {
		JsonObject json = JsonObject.getInstance();
		json.setData(areaServiceService.selectList(new EntityWrapper<SecurityChannelAreaService>()
				.where("area_id={0}", countryId).andNewSimple("status", 1)));
		setJsonMessage(json);
		return json;
	}

	/**
	 * @desc 3.获取自送网点,网点服务列表
	 * @param serviceId
	 * @return
	 */
	@RequestMapping(value = "/serviceNetworkItem/{serviceId}")
	public JsonObject getServiceNetworkItem(@PathVariable("serviceId") Integer serviceId) {
		JsonObject json = JsonObject.getInstance();
		json.setPage(areaServiceNetworkService
				.getNetworkList(SecurityChannelAreaServiceNetworkDTO.builder().status(1).serviceId(serviceId).build()));
		setJsonMessage(json);
		return json;
	}

	/**
	 * @desc 3.获取取件费 , 取件合作商服务列表
	 * @param serviceId
	 * @return
	 */
	@RequestMapping(value = "/servicePickupItem/{serviceId}")
	public JsonObject getServicePickupItem(@PathVariable("serviceId") Integer serviceId) {
		JsonObject json = JsonObject.getInstance();
		json.setPage(areaServicePartnerService.getServicePartnerList(
				SecurityChannelAreaServicePartnerDTO.builder().status(1).serviceId(serviceId).build()));
		setJsonMessage(json);
		return json;
	}

}
